package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppImg;
import com.ruoyi.background.service.IAppImgService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小程序图片Controller
 *
 * @author susu
 * @date 2024-08-04
 */
@RestController
@RequestMapping("/applet/appImg")
public class AppImgController extends BaseController {
    @Autowired
    private IAppImgService appImgService;

    /**
     * 查询小程序图片列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appImg:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppImg appImg) {
        startPage();
        List<AppImg> list = appImgService.selectAppImgList(appImg);
        return getDataTable(list);
    }

    /**
     * 导出小程序图片列表
     */
    @PreAuthorize("@ss.hasPermi('applet:appImg:export')")
    @Log(title = "小程序图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppImg appImg) {
        List<AppImg> list = appImgService.selectAppImgList(appImg);
        ExcelUtil<AppImg> util = new ExcelUtil<AppImg>(AppImg.class);
        util.exportExcel(response, list, "小程序图片数据");
    }

    /**
     * 获取小程序图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:appImg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appImgService.selectAppImgById(id));
    }

    /**
     * 新增小程序图片
     */
    @PreAuthorize("@ss.hasPermi('applet:appImg:add')")
    @Log(title = "小程序图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppImg appImg) {
        return toAjax(appImgService.insertAppImg(appImg));
    }

    /**
     * 修改小程序图片
     */
    @PreAuthorize("@ss.hasPermi('applet:appImg:edit')")
    @Log(title = "小程序图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppImg appImg) {
        return toAjax(appImgService.updateAppImg(appImg));
    }

    /**
     * 删除小程序图片
     */
    @PreAuthorize("@ss.hasPermi('applet:appImg:remove')")
    @Log(title = "小程序图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appImgService.deleteAppImgByIds(ids));
    }
}
